package rhc.discribute.node.connecter.schedule;

import org.apache.log4j.Logger;
import org.quartz.Job;

import rhc.discribute.node.sendMessage.SendMessageData;
import rhc.discribute.util.ScheduleUpdate;
import rhc.discribute.util.ScheduleUpdateUtil;

/**一条消息发送后会持有一个分布式锁等待对方接收后才会释放锁，如果对方没有接收则会一直持有锁造成不能再发消息到该节点
 * 为了避免这种情况会在发送消息5秒后执行该检查任务，如果没有接收成功则主动释放，该类携带数据和定时任务信息
 * @author rhc
 *
 */
public class SendMessageFailCheckSchedule implements ScheduleUpdate{

	private static final Logger logger=Logger.getLogger(SendMessageFailCheckSchedule.class);
	
	private SendMessageData dataMap;
	
	/**
	 * 等待5秒后检测对方是否接收
	 */
	public static final int waitSeconds=3;
	
	public SendMessageFailCheckSchedule(SendMessageData dataMap){
		this.dataMap=dataMap;
	}
	
	public void run(){
		ScheduleUpdateUtil.runJob(this);
	}
	
	@Override
	public String getId() {
		return this.toString();
	}

	@Override
	public ScheduleType getScheduleType() {
		return ScheduleType.TIMEINTERVAL;
	}

	@Override
	public int getTimeInterval() {
		return waitSeconds;
	}

	@Override
	public boolean isForever() {
		return false;
	}

	@Override
	public int runCount() {
		return 1;
	}

	@Override
	public boolean startNow() {
		return false;
	}

	@Override
	public String getCron() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Class<? extends Job> getJobClass() {
		return SendMessageFailCheckJob.class;
	}

	public SendMessageData getDataMap() {
		return dataMap;
	}

	public void setDataMap(SendMessageData dataMap) {
		this.dataMap = dataMap;
	}

}
